-
Notifications
You must be signed in to change notification settings - Fork 437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support loading dynamic libraries from multiple paths and try more paths in default loader #1864
base: master
Are you sure you want to change the base?
Conversation
…ths in default loader
For reference, the list of paths is the same as used by SDL. This makes development on macos using the home-brew molten-vk package simpler since with this update the dylib can be found automatically (assuming paths are configured correctly). Otherwise you are forced to load the FunctionPointers yourself. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this is probably a good change for MacOS. Would other platforms also have multiple paths?
i.e. sdl's wayland code has this:
#if defined(__OpenBSD__)
#define DEFAULT_VULKAN "libvulkan.so"
#else
#define DEFAULT_VULKAN "libvulkan.so.1"
#endif
let get_proc_addr = { | ||
let ptr: *mut c_void = dl | ||
.symbol("vkGetInstanceProcAddr") | ||
// Arguably we could continue trying subsequent paths here, but we don't | ||
// expect to find a matching filename without the right contents, so better | ||
// to fail here, especially since an unknown library is now loaded into the | ||
// process. | ||
.map_err(|_| { | ||
LoadingError::MissingEntryPoint("vkGetInstanceProcAddr".to_owned()) | ||
})?; | ||
mem::transmute(ptr) | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DynamicLibrary
seems to implement Drop
, so would it be safe to continue attempting paths?
https://docs.rs/shared_library/0.1.9/shared_library/dynamic_library/struct.DynamicLibrary.html#impl-Drop
I don't know much about loading library, so I don't know what is safe and what isn't.
get_proc_addr, | ||
}) | ||
} | ||
None => Err(LoadingError::LibraryLoadFailure(errors.join(" "))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I not sure I am a huge fan of the space separated errors. shared_library
isn't very helpful with just returning a String
. Perhaps the errors should be a Vec<LoadingError { path: Path, error: String }>
?
Vulkano uses Ash, and Ash has its own loading implementation. Perhaps these changes would be useful for them as well? I've been considering making Vulkano use Ash's loading code so then Vulkano would also benefit. |
Change the DynamicLibraryLoader::new interface to accept a slice of paths
instead of a single path. It tries to load them in order, using the first one it is
able to load. Update the auto_loader implementation to use the updated
version, including a larger set of paths for the Vulkan library.
Describe in common words what is the purpose of this change, related
Github Issues, and highlight important implementation aspects.
Please put changelog entries in the description of this Pull Request
if knowledge of this change could be valuable to users. No need to put the
entries to the changelog directly, they will be transferred to the changelog
files(
CHANGELOG_VULKANO.md
andCHANGELOG_VK_SYS.md
)by maintainers right after the Pull Request merge.
Entries for Vulkano changelog:
**Breaking** Breaking entry description.
Non-breaking entry description.
...Entries for VkSys changelog:
Entry 1.
Entry 2.
...Run
cargo fmt
on the changes.Make sure that the changes are covered by unit-tests.
Update documentation to reflect any user-facing changes - in this repository.